package com.xjrsoft.module.customerTwo.EMP.room_tools.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.utils.DataTransUtil;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.EMP.room_tools.dto.TRoomToolsDto;
import com.xjrsoft.module.customerTwo.EMP.room_tools.dto.SaveTRoomToolsFormDataDto;
import com.xjrsoft.module.customerTwo.EMP.room_tools.vo.TRoomToolsVo;
import com.xjrsoft.module.customerTwo.EMP.room_tools.vo.TRoomToolsListVo;
import com.xjrsoft.module.customerTwo.EMP.room_tools.dto.TRoomToolsListDto;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.EMP.room_tools.entity.TRoomTools;
import com.xjrsoft.module.customerTwo.EMP.room_tools.vo.TRoomToolsVo;
import com.xjrsoft.module.customerTwo.EMP.room_tools.service.ITRoomToolsService;

/**
 *  控制器
 *
 * @author lisen
 * @since 2023-12-07
 */
@RestController
@AllArgsConstructor
@RequestMapping("/room_tools")
@Api(value = "房间物品", tags = "房间物品接口")
public class TRoomToolsController {


	private final ITRoomToolsService tRoomToolsService;


	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入tRoomTools")
	@SaCheckPermission(value = {"room_tools:view", "room_tools:modify"}, mode = SaMode.OR)
	public Response<TRoomToolsVo> getFormData(@PathVariable String id) {
		// 主表数据
		TRoomTools tRoomTools = tRoomToolsService.getById(id);
		TRoomToolsVo tRoomToolsVo = BeanUtil.copy(tRoomTools, TRoomToolsVo.class);
		return Response.ok(tRoomToolsVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入tRoomTools")
		public Response<PageOutput<TRoomToolsListVo>> getPageList(TRoomToolsListDto listDto) {
		IPage<TRoomTools> page = tRoomToolsService.getPageList(listDto);
		List<TRoomToolsListVo> records = BeanUtil.copyList(page.getRecords(), TRoomToolsListVo.class);
			// 转换列表数据
		DataTransUtil.transListShowData(records);
			// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入tRoomTools")
	@SaCheckPermission("room_tools:add")
	public Response save(@RequestBody SaveTRoomToolsFormDataDto formDto) {
		TRoomToolsDto tRoomToolsDto = formDto.getTRoomToolsDto();
		TRoomTools tRoomTools = BeanUtil.copy(tRoomToolsDto, TRoomTools.class);
		Long dataId = tRoomToolsService.addTRoomTools(tRoomTools);
		return dataId == null ? Response.notOk() : Response.ok(dataId);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入tRoomTools")
	@SaCheckPermission("room_tools:modify")
	public Response update(@PathVariable Long id, @RequestBody SaveTRoomToolsFormDataDto formDto) {
		TRoomToolsDto tRoomToolsDto = formDto.getTRoomToolsDto();
		TRoomTools tRoomTools = BeanUtil.copy(tRoomToolsDto, TRoomTools.class);
		return Response.status(tRoomToolsService.updateTRoomTools(id, tRoomTools));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"room_tools:batchDelete", "room_tools:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(tRoomToolsService.delete(ids));
	}


}
